
 /*
author:
time : 2021年10月26日
 */ 
<template>
  <div>
    <!-- 用户点评管理 -->

    <!-- 搜索框 -->
    <div style="margin-top: 15px">
      <el-input placeholder="请输入内容" v-model="input" class="input">
        <el-button
          class="btn"
          slot="append"
          icon="el-icon-search"
          @click="search"
        ></el-button>
      </el-input>
    </div>
    <!-- 表格 -->
    <div class="content_table">
      <el-table :data="adminList" style="width: 99%">
        <el-table-column :width="150" label="ID">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column :width="150" label="用户名">
          <template slot-scope="scope">
            <span>{{ scope.row.username }}</span>
          </template>
        </el-table-column>
        <el-table-column :width="150" label="产品名">
          <template slot-scope="scope">
            <span>{{ scope.row.product_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="评论内容">
          <template slot-scope="scope">
            <span>{{ scope.row.content }}</span>
          </template>
        </el-table-column>
        <el-table-column :width="150" label="评分（星星）">
          <template slot-scope="scope">
            <span>{{ scope.row.Score }}</span>
          </template>
        </el-table-column>
        <el-table-column :width="150" label="外观评分">
          <template slot-scope="scope">
            <span>{{ scope.row.appearance }}</span>
          </template>
        </el-table-column>
        <el-table-column :width="150" label="性能评分">
          <template slot-scope="scope">
            <span>{{ scope.row.performance }}</span>
          </template>
        </el-table-column>
        <el-table-column :width="150" label="价格">
          <template slot-scope="scope">
            <span>{{ scope.row.price }}</span>
          </template>
        </el-table-column>

        <el-table-column :width="150" label="操作">
          <template slot-scope="scope">
            <el-popconfirm
                  confirm-button-text='确定'
                  cancel-button-text='取消'
                  icon="el-icon-info"
                  icon-color="red"
                  title="确定删除这一条数据吗？"
                  @onConfirm="del(scope.row.id)"
                >
            <el-button slot="reference" size="mini" type="danger" >删除</el-button>
          </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <Page :page=page :count=count @pageChange=pageChange /> -->
    <div class="block">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="page"
        :page-size="pageSize"
        layout="total, prev, pager, next,jumper"
        :total="count"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
// import Page from "@/components/Page.vue";
import {
  getCommentSer,
  getCommentDel,
} from "@/api/table";

export default {
  components: {
    // Page
  },
  data() {
    return {
      input: "",

      value: "100",

      // 是否启用,默认启用
      value1: true,
      adminList: [],
      //查询关键字
      keyName: "",

      // 数据库总页数

      count: 0,
      // 当前页数
      page: 1,
      // 每页显示几条数据

      pageSize: 10,

      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        id: null,
        username: "",
        product_name: "",
        Score: "",
        content: "",
        appearance: "",
        performance: "",
        price: "",
      },
      // 模态框输入长度
      formLabelWidth: "80px",
      // 判断是新增加还是修改,默认是添加
      isEdit: false,
    };
  },

  created() {
    this.getDate();
    // console.log(this.count,this.page,this.pageSize);
  },

  methods: {
    handleCurrentChange() {
      console.log("adad", this.count, this.page);
      this.getDate();
    },
    // 获取用户点评数据的方法
    getDate() {
      const params = {
        page: this.page,
        number: this.pageSize,
        username: this.keyName,
      };
      getCommentSer(params).then((res) => {
        console.log(res);
        if (res.code === 0) {
          this.adminList = res.data;
          this.count = res.count;
        } 
        if (res.code === 4004) {
            this.adminList = res.data;
            this.count = res.count;
            this.page=res.page;
          } 
        });
    },
    // 根据关键字查询
    search() {
      this.keyName = this.input;
      this.getDate();
    },

    // 删除用户点评

    del(id) {
      // this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(() => {
          getCommentDel(id).then((res) => {
            if (res.code === 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              // 删除后重新渲染
              this.getDate();
            }
          });
        // })
        // .catch(() => {
        //   this.$message({
        //     type: "info",
        //     message: "已取消删除",
        //   });
        // });
    },
    pageChange(page) {
      console.log(page);
      this.page = page;
      this.getDate();
    },
  },
};
</script>

<style lang="scss" scoped>
.fa {
  margin-right: 5px;
}

.bread {
  width: 100%;
  height: 30px;
  padding: 10px 0;
  display: flex;
  padding-left: 10px;
  align-items: center;
  .el-breadcrumb {
    line-height: 30px;
    width: 100%;
    background-color: #fff;
  }
}
.input {
  background-color: #fff;
  width: 450px;
  margin: 30px 0px 10px 90px;
}
.add {
  background-color: rgb(133, 190, 228);
  color: white;
  border: none;
  line-height: 38px;
  border-radius: 5px;
  margin-left: 10px;
}
.content_table {
  width: 90%;
  margin: 10px auto;
}
.block{
  margin:10px 35px;
}
.el-pagination {
  padding: 5px 50px;
}
.el-button{
  margin-right: 10px;
}
</style> 